package cn.chenc.framework.jpa.repository;

import cn.chenc.framework.jpa.exception.RepositoryException;
import cn.chenc.framework.jpa.model.PageInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.NoRepositoryBean;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 　@description: Jpa扩展-BaseRepository
 * 　@author secret
 * 　@date 2021/6/5 22:12
 *
 */
@NoRepositoryBean
public interface BaseRepository <T, ID extends Serializable> extends JpaRepository<T, ID>, JpaSpecificationExecutor<T> {
    T get(ID id) throws RepositoryException;

    T update(T t) throws RepositoryException;

    T saveOrUpdate(ID id, T t) throws RepositoryException;

    void delete(ID id) throws RepositoryException;

    void deleteBatchByIds(Collection<ID> ids) throws RepositoryException;

    T getOneByObject(T t) throws RepositoryException;

    List<T> getListByObject(T t) throws RepositoryException;

    List<T> getListByObject(T t, Sort sort) throws RepositoryException;

    Page<T> getListByObject(T t, Pageable pageable) throws RepositoryException;

    List<T> getListBySql(String sql) throws RepositoryException;

    List<T> getListBySql(String sql, Class<T> clzss) throws RepositoryException;

    PageInfo getListBySql(String sql, PageInfo pageable) throws RepositoryException;

    PageInfo getListBySql(String sql, PageInfo pageable, Map<String, Object> searchMap) throws RepositoryException;

    List<Map<String, Object>> getListMapBySql(String sql) throws RepositoryException;

    List<Map<String, Object>> getListMapBySql(String sql, Map<String, Object> searchMap) throws RepositoryException;

    PageInfo getListMapBySql(String sql, PageInfo pageable) throws RepositoryException;

    PageInfo getListMapBySql(String sql, PageInfo pageable, Map<String, Object> searchMap) throws RepositoryException;

    Map<String, Object> getSingleMapBySql(String sql) throws RepositoryException;

    int insertBySql(String sql) throws RepositoryException;

    int insertBySql(String sql, Map<String, Object> paraMap) throws RepositoryException;

    int updateBySql(String sql) throws RepositoryException;

    int deleteBySql(String sql) throws RepositoryException;

    int executeBySql(String sql) throws RepositoryException;

    int executeBySql(List<String> sqls) throws RepositoryException;

    int getCountBySql(String sql, Map<String, Object> searchMap) throws RepositoryException;

    List<String> getColumnsBySql(String sql) throws RepositoryException;

    List<Map<String, String>> getColumnsAndTypeBySql(String sql) throws RepositoryException;

    List<String> getColumnsByTableName(String tableName) throws RepositoryException;
}
